//
//  UILabel+VerticalAlign.m
//  Feeder
//
//  Created by Diego Acosta on 9/5/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UILabel+VerticalAlign.h"


@implementation UILabel(VerticalAlign)

- (void)alignTop {
	
    CGSize fontSize = [self.text sizeWithFont:self.font];
	
    double finalHeight = fontSize.height * self.numberOfLines;
    double finalWidth = self.frame.size.width;    //expected width of label
		
    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight)
									 lineBreakMode:self.lineBreakMode];
	
    int newLinesToPad = (finalHeight  - theStringSize.height) / fontSize.height;
	
    for(int i = 0; i< newLinesToPad; i++) {
		
        self.text = [self.text stringByAppendingString:@"\n\n"];
    }
}

- (void)alignBottom {
	
    CGSize fontSize = [self.text sizeWithFont:self.font];
	
    double finalHeight = fontSize.height * self.numberOfLines;
    double finalWidth = self.frame.size.width;    //expected width of label
	
    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight)
									 lineBreakMode:self.lineBreakMode];
	
    int newLinesToPad = (finalHeight  - theStringSize.height) / fontSize.height;
	
    for(int i = 0; i< newLinesToPad; i++) {
		
        self.text = [NSString stringWithFormat:@"\n\n%@",self.text];
    }
}

@end
